/* Include files. */

extern "C" { 
	#include "standard.h"
	#include "util.h"
	#include "debug.h"
} 

#include "event.h"
#include "timercore.h"
#include "subsystemcore.h"

/* Local function declarations. */

/* Macro API definitions. */

/* Global variable declarations. */

/* Type definitions. */

/* Local function definitions. */

event::event(u32 session, lua_State *L)
		:_L(L), _session(session)
{
	_begin_time = currentMsTime();
	lua_getfield(_L, LUA_REGISTRYINDEX, "sub");
	subSystem *sub = (subSystem*)lua_touserdata(_L, -1);
	if (sub == NULL) {
		ERROR("subsystem error");
		return;
	}
	_sub = sub;
	_sub->addEvent(this);
}

event::~event() {
	if (_sub != NULL)
		_sub->removeEvent(this);
}

u64 event::costTime()
{
	u64 cur = currentMsTime();
	return cur - _begin_time;
}

ubusEvent::ubusEvent(string name, u32 session, lua_State *L)
	:event(session, L),_name(name)
{
#ifdef U_LOOP
	memset(&_listener, 0, sizeof(_listener));  
#endif
}

ubusEvent::~ubusEvent() 
{

}

